const path = require('path')
const VConsolePlugin = require('vconsole-webpack-plugin')

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  lintOnSave: true,
  configureWebpack: config => {
    return {
      optimization: {
        minimize: true
      },
      plugins: [
        new VConsolePlugin({
          filter: [],
          enable: process.env.NODE_ENV !== 'production'
        })
      ],
      resolve: {
        extensions: ['.js', '.vue', '.json'],
        alias: {
          '@': resolve('src'),
          src: resolve('src'),
          common: resolve('src/common'),
          service: resolve('src/common/service'),
          utils: resolve('src/common/utils'),
          config: resolve('src/common/config'),
          components: resolve('src/components'),
          'components-base': resolve('src/components-base')
        }
      }
    }
  },
  devServer: {
    // 配置转发代理
    // open: true, // 是否打开浏览器
    port: 8080,
    overlay: {
      warnings: true,
      errors: true
    },
    // 调试时允许内网穿透，让外网的人访问到本地调试的H5页面
    disableHostCheck: true,
    proxy: {
      '/api': {
        target: 'http://10.10.1.6:6100/', // 需要跨域的域名
        changeOrigin: true,
        secure: false, // 设置支持https协议的代理
        pathRewrite: {
          '^/api': '/api' // 匹配请求路径里面有 /api 替换成 http://10.10.1.6:6100/api
        }
      },
      '/testapi': {
        target: 'http://10.10.1.99:9085/', // 需要跨域的域名
        changeOrigin: true,
        secure: false, // 设置支持https协议的代理
        pathRewrite: {
          '^/testapi': '/api' // 匹配请求路径里面有 /api 替换成 http://10.10.1.99:9085/api
        }
      }
    }
  }
}
